package com.bjsxt.controller.system;

import com.bjsxt.aspectj.annotation.Log;
import com.bjsxt.aspectj.enums.BusinessType;
import com.bjsxt.dto.RegisteredItemDto;
import com.bjsxt.service.RegisteredItemService;
import com.bjsxt.utils.ShiroSecurityUtils;
import com.bjsxt.vo.AjaxResult;
import com.bjsxt.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author:liao
 * @Description:TODO 挂号费用管理
 * @date:2020/12/17
 */
@RestController
@RequestMapping("system/registeredItem")
public class RegisteredItemController {

    @Autowired
    private RegisteredItemService registeredItemService;

    // 分页查询
    @GetMapping("listRegisteredItemForPage")
    public AjaxResult listRegisteredItemForPage(RegisteredItemDto registeredItemDto){
        DataGridView dataGridView = registeredItemService.listRegisteredItemPage(registeredItemDto);
        return AjaxResult.success("查询成功",dataGridView.getData(),dataGridView.getTotal());
    }

    // 添加
    @PostMapping("addRegisteredItem")
    @Log(title = "添加挂号项目",businessType = BusinessType.INSERT)
    public AjaxResult addRegisteredItem(@Validated RegisteredItemDto registeredItemDto){
        registeredItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(registeredItemService.addRegisteredItem(registeredItemDto));
    }

    // 修改
    @PutMapping("updateRegisteredItem")
    @Log(title = "修改挂号项目",businessType = BusinessType.UPDATE)
    public AjaxResult updateRegisteredItem(@Validated RegisteredItemDto registeredItemDto){
        registeredItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(registeredItemService.updateRegisteredItem(registeredItemDto));
    }

    // 根据id查询
    @GetMapping("getRegisteredItemById/{regItemId}")
    public AjaxResult getRegisteredItemById(@PathVariable Long regItemId){
        return AjaxResult.success(registeredItemService.getOne(regItemId));
    }

    // 删除
    @DeleteMapping("deleteRegisteredItemByIds/{regItemId}")
    @Log(title = "删除挂号项目",businessType = BusinessType.DELETE)
    public AjaxResult deleteRegisteredItemByIds(@PathVariable Long[] regItemId){
        return AjaxResult.toAjax(registeredItemService.deleteRegisteredItemByIds(regItemId));
    }

    // 查询全部有效的
    @GetMapping("selectAllRegisteredItem")
    public AjaxResult selectAllRegisteredItem(){
        return AjaxResult.success(registeredItemService.queryAllRegisteredItems());
    }
}
